package com.vogue.supplymall.common.domain.validate;

import java.io.Serializable;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import com.vogue.supplymall.common.domain.tool.MessageSourceUtils;
import com.vogue.supplymall.common.exception.AttributesNotNullableException;  

@SuppressWarnings("serial")
public class NotEmptyValidator implements ConstraintValidator<NotEmpty, String>,Serializable{
		
	@Autowired
	protected MessageSourceUtils messageSourceUtils;
	
	private String attrName = "name";
	
	@Override
	public void initialize(NotEmpty constraintAnnotation) {
		// TODO Auto-generated method stub
		attrName = messageSourceUtils.getMessage(com.vogue.supplymall.common.constant.ConstantBean.GLOBAL_SYSTEM
				+ constraintAnnotation.name(), null);
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		// TODO Auto-generated method stub
		if(StringUtils.isEmpty(value)) {
			throw new AttributesNotNullableException(attrName);
		}
		return true;
	}
	
}
